package hxg.tcptest.dome3;

import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author HeXiangGuang
 * @create 2021-06-30 11:48
 * TCP实现多个客户端请求
 */
public class TcpServer {
    public static void main(String[] args) throws Exception{
        //创建ServerSocket
        ServerSocket listener = new ServerSocket(10086);
        //调用accept(),接收客户端请求
        System.out.println("服务器已经启动。。。。。。");
        //这里有个bug，因为是在死循环中开的线程，所以这里就算子线程完成工作关闭资源后该程序还不会停止
        while (true){
            Socket socket = listener.accept();
            System.out.println(socket.getInetAddress() + "进来了-----");
            SocketThread socketThread = new SocketThread(socket);
            socketThread.start();
//            if (! socketThread.flag){
//                break;
//            }
        }
/*            Socket socket = listener.accept();
            System.out.println(socket.getInetAddress() + "进来了-----");
            SocketThread socketThread = new SocketThread(socket);
            socketThread.start();*/


        //
    }
}
